package com.yc.spring;

import com.yc.spring.bbs.bean.User;
import com.yc.spring.bbs.bean.YcUser;
import org.springframework.context.annotation.*;

// 配置类 === beans.xml
@Configuration  // 配置类注解
// 组件扫描: 扫描指定包下组件(含子包)
@ComponentScan("com.yc")
// 开启aspect自动代理
@EnableAspectJAutoProxy
public class IocConfig {

    // <bean> ==> Bean 方法
//    <bean class="com.yc.spring.bbs.bean.User" primary="true">
//        <property name="uname" value="zhangsan"></property>
//    </bean>
    @Bean
    @Primary  // primary="true"
    User user(){
        User user = new User();
        user.setUname("zhangsan");
        return user;
    }

//    <bean id="user1" class="com.yc.spring.bbs.bean.YcUser"
//    factory-method="create"></bean>
    @Bean("user1")
    //@Primary  // primary="true"
    @Lazy     // lazy-init
    @Scope("prototype") // scope="prototype"
    User user1(){
        User user = YcUser.create();
        user.setUname("李四");
        return user;
    }



}
